using System;
using System.Collections.Generic;
using System.Text;

namespace CodePlex.SpaceBlock.Tasks
{

    abstract public class GenericTask
    {


        public abstract bool Execute();




        public event EventHandler<MessageEventArgs> Message;

        private readonly Dictionary<string, string> _values = new Dictionary<string, string>();

        public string GetProperty(string name)
        {
            if (!_values.ContainsKey(name))
            {
                return null;
            }
            return _values[name];
        }

        public void SetProperty(string name, string value)
        {
            _values.Add(name, value);
        }

        protected void LogError(string message, params object[] parameters)
        {
            OnMessage(MessageLevel.Error,message, parameters);
        }

        protected void LogInfo(string message, params object[] parameters)
        {
            OnMessage(MessageLevel.Info,message, parameters);
        }

        protected void LogWarning(string message, params object[] parameters)
        {
            OnMessage(MessageLevel.Warning, message, parameters);
        }
       


        private void OnMessage(MessageLevel level, string message, params object[] parameters)
        {
            if (this.Message != null)
            {
                this.Message(this, new MessageEventArgs(level, string.Format(message, parameters)));
            }
        }

    }
}
